home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / bin / list.c < prev    next >
C/C++ Source or Header  |  1999-12-06  |  3KB  |  98 lines

  1. #include <pragma/noviasys_lib.h>
  2. #include <pragma/exec_lib.h>
  3. #include <pragma/dos_lib.h>
  4. #include <stdio.h>
  5. #include <novia/novia_portdata.h>
  6.  
  7. struct Library *NoviaSysBase;
  8.  
  9. void ioprintf(const char *string, ...)
  10. {
  11.     char *buffer=AllocVec(10000,MEMF_ANY|MEMF_CLEAR);
  12.     if (buffer)
  13.     {
  14.         vsprintf(buffer, string, unsigned int(&string + 1));
  15.         Writeio(buffer,-1);
  16.         FreeVec(buffer);
  17.     }
  18. }
  19.  
  20. void main()
  21. {
  22.     if ((NoviaSysBase = OpenLibrary("noviasys.library", 0)))
  23.     {
  24.         struct PortData *cport = (struct PortData *)FindTask(NULL)->tc_UserData;
  25.         LONG result = FALSE;
  26.         ItemEntryBlock *ieb;
  27.         char        buf[120];
  28.         char        bits[9];
  29.         char        size[20];
  30.         char        date[20];
  31.         if (cport && cport->currentdir)
  32.         {
  33.             List  newlist;
  34.             ItemEntryBlock *currentieb;
  35.             ULONG cmpresult;
  36.             BOOL quit;
  37.             NewList(&newlist);
  38.             ieb = cport->itementrylist.lh_Head;
  39.             while (ieb->ln_Succ)
  40.             {
  41.                 strcpy(bits,"--------");
  42.                 if (ieb->Protection & FIBF_SCRIPT)
  43.                     bits[1]='s';
  44.                 if (ieb->Protection & FIBF_PURE)
  45.                     bits[2]='p';
  46.                 if (ieb->Protection & FIBF_ARCHIVE)
  47.                     bits[3]='a';
  48.                 if (ieb->Protection & FIBF_READ)
  49.                     bits[4]='r';
  50.                 if (ieb->Protection & FIBF_WRITE)
  51.                     bits[5]='w';
  52.                 if (ieb->Protection & FIBF_EXECUTE)
  53.                     bits[6]='e';
  54.                 if (ieb->Protection & FIBF_DELETE)
  55.                     bits[7]='d';
  56.     
  57.                 if (ieb->ItemType == ITEMTYPE_SUBBOARD)
  58.                     strcpy(size,"Dir");
  59.                 else
  60.                 {
  61.                     if (ieb->Size >= 100000)
  62.                     {
  63.                         if (ieb->Size >= 10000000)
  64.                         {
  65.                             double erg = double(ieb->Size) / (1024 * 1024);
  66.                             sprintf(size,"%##.1g MB",erg);
  67.                         }
  68.                         else
  69.                         {
  70.                             double erg = double(ieb->Size) / 1024;
  71.                             sprintf(size,"%##.1g KB",erg);
  72.                         }
  73.                     }
  74.                     else
  75.                         sprintf(size,"%d   ",ieb->Size);
  76.                 }
  77.                 DateToString(date,&ieb->LastChange, 0);
  78.                 if (cport->currentdir->NetworkType)
  79.                 {
  80.                     if (ieb->selected)
  81.                         ioprintf("*%-3d %-3u %-40s %8s %s %s\n",ieb->IDNumber, ieb->IPNumber,ieb->Title,size,date,ieb->Comment);
  82.                     else
  83.                         ioprintf(" %-3d %-3u %-40s %8s %s %s\n",ieb->IDNumber, ieb->IPNumber,ieb->Title,size,date,ieb->Comment);
  84.                 }
  85.                 else
  86.                 {
  87.                     if (ieb->selected)
  88.                         ioprintf("*%-3d %-3u %-40s %8s %s %s\n",ieb->IDNumber, ieb->IPNumber,ieb->Title,size,bits,date);
  89.                     else
  90.                         ioprintf(" %-3d %-3u %-40s %8s %s %s\n",ieb->IDNumber, ieb->IPNumber,ieb->Title,size,bits,date);
  91.                 }
  92.                 ieb = ieb->ln_Succ;
  93.             }
  94.             ioprintf("%d file(s) - %d directory(s) - %u bytes listed.\n",cport->itementrylist.files,cport->itementrylist.dirs,cport->itementrylist.size);
  95.         }
  96.         CloseLibrary(NoviaSysBase);
  97.     }
  98. }